from lattice_functions import *
from numpy import array
from analysis_functions import *
from utility_functions import *
import gc
import sys
'''
Analysis Script:
Get:
	* Amount of concepts
	* Stability mean
	* 100 more stable concepts
	* 100 more stable concepts stability mean
	* Coincident concepts
	* Levels
'''
#<get_this_data>
top = 100
amount_concepts = 0
stability_mean = 0
top_concepts = []
top_concepts_stab = 0
coincident_concepts = []
levels = 0
#</get_this_data>
gc.enable()
real_lattice = "data/real/handmade-inv.lat"
print "Reading Real Lattice"

reale, reallev, realmaxlev, realat, realden, realtime = readLattice(real_lattice)
comparer = {}
for e in reale:
	comparer[str(reale[e]["attributes"])] = e

lattice = ""
if len(sys.argv)<2:
	print "\n*** usage:",sys.argv[0]," [path]"
	exit()
else:
	path = sys.argv[1]
db = path.split("/")[len(path.split("/"))-2]
filename = "data/"+db+"_data_compile.txt"
f = open(filename,"w")
write_data(f,["k","d","Levels","Concepts","Stability",str(top)+" stab","coincidental","atts","density","time"])
f.close()
files = get_files_on_path(path)
for lattice in files:
	print lattice
	keys = lattice.replace(".lat","").split("-")
	k = int(keys[1].replace("k",""))
	d = float(keys[2].replace("a",""))
	data,levels,maxlev,atts,density,time = readLattice(path+lattice)
	analytic = AnalyticThing(data,top)
	'''PRINT DATA'''
	levels = maxlev
	amount_concepts=analytic.get_amount_of_concepts()
	stability_mean = analytic.get_stability_mean()
	top_concepts_stab = analytic.get_top_concepts_stability()
	coincidental_concepts = analytic.compare_with_other_data_and_log(comparer,lattice+".txt")
	f = open(filename,"a")
	print filename
	write_data(f,[k,d,levels,amount_concepts,stability_mean,top_concepts_stab,coincidental_concepts,atts,density,time])
	f.close()
	del analytic
	del data
	del levels 
	del maxlev
	gc.collect()
